package com.robert.maps.utils;

import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.andnav.osm.util.GeoPoint;

public class POI implements Comparable<POI>{
	static SimpleDateFormat FORMATTER = 
		new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
	
	//joeng start
	private String Name;
	private String description;
	private ArrayList GeoPoint; 

	public String getName(){
		return Name;
	}
	public void setName(String Name){
		this.Name = Name.trim().replaceAll("\\<.*?\\>", "");
	}
	public ArrayList getGeoPoint(){
		return GeoPoint;
	}
	public void setGeoPoint(String GeoPos){
		String[] sGeoPos = GeoPos.split("\n");
		if (GeoPoint == null)
			GeoPoint = new ArrayList();
		for (int i = 0; i < sGeoPos.length; i ++){
			if (sGeoPos[i].trim().length() != 0){
				try{
				String[] sGeoPoint = sGeoPos[i].split(",");
				if (sGeoPoint.length >1){
					GeoPoint.add(new GeoPoint((int) (Double.parseDouble(sGeoPoint[1]) * 1E6), 
							(int) (Double.parseDouble(sGeoPoint[0]) * 1E6)));
				}
				}
				catch(Exception e) {
					String abc = e.getMessage();
				}
			}
		}
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description.trim().replaceAll("\\<.*?\\>", "");
	}

	
	public POI copy(){
		POI copy = new POI();
		copy.Name = Name;
		copy.description = description;
		copy.GeoPoint = (ArrayList) GeoPoint.clone();
		return copy;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Name: ");
		sb.append(Name);
		sb.append('\n');
		sb.append("Description: ");
		sb.append(description);
		sb.append('\n');
		sb.append("Latitude: ");
		sb.append(((GeoPoint) GeoPoint.get(0)).getLatitudeE6());
		sb.append('\n');
		sb.append("Longitude: ");
		sb.append(((GeoPoint) GeoPoint.get(0)).getLongitudeE6());
		return sb.toString();
	}

		
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		POI other = (POI) obj;
		if (Name == null) {
			if (other.Name != null)
				return false;
		} else if (!Name.equals(other.Name))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (GeoPoint == null) {
			if (other.GeoPoint != null)
				return false;
		} else if (!GeoPoint.equals(other.GeoPoint))
			return false;
		return true;
	}

	public int compareTo(POI another) {
		if (another == null) return 1;
		// sort descending, most recent first
		return another.Name.compareTo(Name);
	}
}
